/********************************************************************************
*																				*
*  Las Venturas Playground - Core/functions.nut									*
*																				*
*  Global functions are located here.											*
*																				*
********************************************************************************/

// Function: Send a usage message with a global format
// Author: Lithirm

function sendPlayerUsageMessage( playerid, sUsage )
{
	sendPlayerMessage( playerid, "[FFFFFFAA]* Usage: " + sUsage, 0xFFFFFFAA, true );
	return 1;
}

// Function: Send an error message with a global format
// Author: Lithirm

function sendPlayerErrorMessage( playerid, sError )
{
	sendPlayerMessage( playerid, "[DC143CFF]* Error: " + sError, 0xDC143CFF, true );
	return 1;
}

function sendInvalidPlayerMessage (playerid, iError)
{
    if (iError == -1) {
        sendPlayerErrorMessage (playerid, "no matching players found.");
    }
    
    else if (iError == -2) {
        sendPlayerErrorMessage (playerid, "too many matching players found.");
    }
}

// Function: Is the string passed on numeric?
// Author: Someone on the IV:MP forums

function isNumeric( string )
{
   try
   {
      string.tointeger();
   }
   catch( string )
   {
      return false;
   }
   
   return true;
}

// Function: Get the players ID from his name. It returns the playerid if the player was valid, -1 if no player was found or invalid parameter passed on. -2 if there are too many matches.
// Author: Pyrokid, edited by Matthias

function getPlayerFromInput(player)
{	
	if (isNumeric(player) && isPlayerConnected(player.tointeger())) 
	{
		return player.tointeger();
	}

    local iMatches = 0;
    local iTargetID = -1;
    player = player.tolower();
		
	for (local i = 0, slots = getPlayerSlots(); i < slots; i++) 
	{
		if (isPlayerConnected(i)) 
		{
            local name = getPlayerName(i).tolower();
            if (name == player) return i;
            
			if (name.find(player) != null)
			{
				iMatches++;
				iTargetID = i;
                
                if (iMatches > 1)
                {
                    iTargetID = -2;
                }
			}
		}
    }
    
	return iTargetID;
}


// Function: Spawn all the vehicles.
// Author: Matthias

function spawnVehicle()
{
	aVehicles.append(createVehicle(65, -343.447662, 1176.119263, 14.146016, 268.219513, 0, 133, 0, 0)); // Police patriot
	aVehicles.append(createVehicle(90, -343.527313, 1172.740479, 14.199832, 268.217010, 0, 0, 0, 0)); // Sultan RS 2
	aVehicles.append(createVehicle(90, -343.501099, 1168.932739, 14.199870, 269.241302, 0, 0, 0, 0)); // Sultan RS 3
	aVehicles.append(createVehicle(90, -343.609344, 1166.145630, 14.199894, 268.305298, 0, 0, 0, 0)); // Sultan RS 4
	aVehicles.append(createVehicle(90, -343.623444, 1162.919067, 14.199799, 269.975037, 0, 0, 0, 0)); // Sultan RS 5
	aVehicles.append(createVehicle(90, -343.633057, 1158.563843, 14.126013, 270.858826, 0, 0, 0, 0)); // Sultan RS 6
        
	aVehicles.append(createVehicle(3, -333.819305, 1156.526489, 14.221210, 268.748199, 126, 126, 1, 1)); // Banshee
	aVehicles.append(createVehicle(17, -324.632965, 1156.928711, 14.238624, 273.387146, 100, 1, 1, 1)); // Comet
	aVehicles.append(createVehicle(18, -313.867645, 1157.084961, 14.248068, 267.556702, 1, 89, 1, 1)); // Coquette
	aVehicles.append(createVehicle(40, -302.791656, 1157.123413, 14.249476, 270.661194, 132, 132, 127, 132)); // Infernus
	aVehicles.append(createVehicle(91, -290.237427, 1156.582153, 14.222496, 269.641907, 56, 1, 1, 1)); // Super GT
	aVehicles.append(createVehicle(95, -281.376251, 1156.519775, 14.222245, 267.204834, 125, 1, 1, 1)); // Turismo
	aVehicles.append(createVehicle(95, -276.197327, 1178.604980, 14.225373, 89.694077, 1, 1, 1, 1)); // Turismo
	aVehicles.append(createVehicle(91, -283.640625, 1178.680298, 14.223532, 89.346024, 35, 1, 1, 1)); // Super GT
	aVehicles.append(createVehicle(40, -292.198181, 1178.493286, 14.229280, 92.256073, 132, 132, 127, 132)); // Infernus
	aVehicles.append(createVehicle(18, -300.689819, 1178.349976, 14.236767, 90.089577, 35, 1, 1, 1)); // Coquette
	aVehicles.append(createVehicle(17, -310.942444, 1178.227905, 14.243614, 95.937233, 1, 1, 1, 1)); // Comet   
        
    // Garage near safehouse
    aVehicles.append(createVehicle(17, 80.072083, 806.802002, 14.732996, 52.333172, 131, 1, 1, 1)); // 
	aVehicles.append(createVehicle(3, 71.970512, 806.263062, 14.732825, 158.601776, 132, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(40, 74.988503, 799.075012, 14.732579, 305.536072, 59, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(95, 61.446747, 806.573792, 14.732187, 133.604416, 1, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(91, 64.698761, 803.985229, 14.732725, 297.042023, 99, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(90, 60.523071, 794.875732, 15.469301, 78.226181, 40, 1, 1, 1)); // (null)        
        
    // Underground garage near Central Park
	aVehicles.append(createVehicle(14, 74.458557, 1114.994385, 2.486223, 359.691467, 133, 63, 125, 89)); // Cavalcade
	aVehicles.append(createVehicle(90, 77.850319, 1115.753052, 2.485435, 359.275879, 24, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(40, 81.357925, 1115.482056, 2.486038, 359.469360, 1, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(27, 84.851608, 1115.453003, 2.486054, 0.088267, 0, 89, 1, 1)); // FBI Buffalo
	aVehicles.append(createVehicle(17, 88.319138, 1115.565918, 2.485528, 0.961295, 1, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(18, 91.852928, 1115.140259, 2.485430, 359.134979, 1, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(39, 95.349136, 1115.179077, 2.486115, 358.711151, 46, 46, 1, 1)); // Huntley Sport
	aVehicles.append(createVehicle(99, 98.638527, 1115.326172, 2.485493, 0.904291, 1, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(16, 102.541504, 1115.617798, 2.485850, 359.591644, 74, 70, 133, 89)); // (null)
	aVehicles.append(createVehicle(79, 67.391365, 1135.895630, 2.486048, 180.371887, 35, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(20, 70.581886, 1136.752197, 2.486533, 179.957825, 59, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(54, 74.535477, 1137.091187, 2.486127, 178.585846, 1, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(43, 77.814636, 1136.655396, 2.486222, 179.574890, 60, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(18, 81.252617, 1136.277222, 2.486300, 181.380707, 54, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(17, 84.749924, 1136.401001, 2.486135, 181.051819, 106, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(62, 88.310555, 1136.714844, 2.486428, 180.714081, 101, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(68, 91.755852, 1136.706543, 2.486559, 179.429108, 103, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(68, 95.174767, 1136.465088, 2.485497, 180.697647, 46, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(90, 98.901871, 1137.015015, 2.486664, 178.606339, 35, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(40, 102.267899, 1137.056152, 2.486621, 180.285004, 36, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(35, 105.834496, 1137.072021, 2.486193, 179.829453, 112, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(6, 109.331627, 1136.397705, 2.486453, 181.758362, 126, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(81, 109.460403, 1142.846069, 2.486187, 359.110565, 42, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(95, 105.948219, 1142.537476, 2.486542, 359.921051, 63, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(3, 102.292450, 1143.034546, 2.486593, 359.752594, 70, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(80, 98.888557, 1142.318115, 2.486675, 359.822327, 60, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(17, 95.270554, 1142.536865, 2.486261, 0.729333, 39, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(91, 91.846138, 1142.971313, 2.485548, 0.142442, 16, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(99, 88.498306, 1142.662964, 2.486245, 358.472351, 91, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(64, 84.922691, 1142.443604, 2.485754, 359.988220, 133, 1, 1, 1)); // Police 2
	aVehicles.append(createVehicle(62, 81.302376, 1142.446045, 2.486187, 359.603485, 128, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(84, 78.041931, 1143.006958, 2.485214, 359.755249, 132, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(91, 74.440170, 1142.659912, 2.485395, 359.936096, 124, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(17, 70.961922, 1142.604004, 2.485592, 1.541062, 29, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(97, 67.547256, 1142.779419, 2.485373, 359.142151, 62, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(39, 70.985619, 1163.780518, 2.485569, 181.091415, 1, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(56, 74.418633, 1163.730469, 2.485590, 180.400558, 106, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(35, 77.785355, 1163.913208, 2.486765, 181.084335, 7, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(28, 81.297302, 1164.020508, 2.486648, 181.840622, 93, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(68, 84.717049, 1163.886719, 2.485696, 180.058151, 86, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(80, 88.271126, 1163.735718, 2.486215, 180.706802, 1, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(17, 91.764656, 1163.733887, 2.485360, 178.145630, 77, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(99, 95.208084, 1163.672729, 2.485425, 179.218369, 53, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(64, 98.777092, 1164.060303, 2.485275, 177.582047, 133, 1, 1, 1)); // Police 2
	aVehicles.append(createVehicle(28, 102.426659, 1164.486084, 2.486356, 181.159729, 80, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(18, 105.774223, 1163.570435, 2.486044, 179.850052, 39, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(39, 109.399948, 1164.388428, 2.485610, 182.073380, 59, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(62, 112.680473, 1164.132080, 2.486373, 179.900787, 1, 1, 1, 1)); // (null)
	aVehicles.append(createVehicle(79, 116.670128, 1163.700928, 2.486068, 179.240646, 1278 1, 1, 1)); // Disabled spot - Sabre GT
	aVehicles.append(createVehicle(97, 67.036934, 1164.146729, 2.486523, 178.215088, 89, 1, 1, 1)); // Disabled spot - Vigero
	aVehicles.append(createVehicle(101, 63.625572, 1163.960815, 2.486771, 180.997269, 45, 1, 1, 1)); // Disabled spot - Voodoo
	aVehicles.append(createVehicle(97, 60.189419, 1163.666992, 2.485555, 180.640869, 29, 1, 1, 1)); // Disabled spot - Vigero
	aVehicles.append(createVehicle(27, 56.502663, 1164.452637, 2.485615, 181.002716, 15, 1, 1, 1)); // Disabled spot - FBI Buffalo
	aVehicles.append(createVehicle(56, 109.545677, 1114.837280, 2.486150, 359.306580, 91, 92, 2, 1)); // Disabled spot - Patriot
	aVehicles.append(createVehicle(81, 105.860840, 1115.151733, 2.486207, 1.416167, 26, 1, 1, 1)); // Disabled spot
	aVehicles.append(createVehicle(17, 71.071251, 1115.521851, 2.486201, 1.626926, 133, 1, 1, 1)); // Disabled spot
	aVehicles.append(createVehicle(3, 67.251572, 1115.276245, 2.486120, 359.998230, 99, 1, 1, 1)); // Disabled spot  
	return 1;
}
